/**
 * User: alesj
 * Date: 18.3.2006
 * Time: 16:01:02
 * 
 * (C) Genera Lynx d.o.o.
 */

package com.alesj.blade.data;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;

/**
 * @author <a href="mailto:ales.justin@genera-lynx.com">Ales Justin</a>
 */
@Entity
@Table(name = "REQUEST")
public class Request implements Serializable {

    Integer id;
    Customer customer;

    Date requestDate;
    Date processDate;
    Date viewDate;

    Rectangle startFrame;
    Set<InputRectangle> startPieces;

    Set<Frame> frames;

    @Transient
    public int getPiecesSize() {
        return getStartPieces().size();
    }

    @Transient
    public int getFramesSize() {
        return getFrames().size();
    }

    @Id
    @GeneratedValue
    @Column(name = "REQUEST_ID")
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @ManyToOne
    @JoinColumn(name = "USER_ID", unique = false, nullable = false, insertable = true, updatable = true)
    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public Date getRequestDate() {
        return requestDate;
    }

    public void setRequestDate(Date requestDate) {
        this.requestDate = requestDate;
    }

    public Date getProcessDate() {
        return processDate;
    }

    public void setProcessDate(Date processDate) {
        this.processDate = processDate;
    }

    public Date getViewDate() {
        return viewDate;
    }

    public void setViewDate(Date viewDate) {
        this.viewDate = viewDate;
    }

    @OneToOne
    @JoinColumn(name = "RECTANGLE_ID", unique = true, nullable = true, insertable = true, updatable = true)
    public Rectangle getStartFrame() {
        return startFrame;
    }

    public void setStartFrame(Rectangle startFrame) {
        this.startFrame = startFrame;
    }

    @OneToMany(mappedBy = "request", fetch = FetchType.EAGER)
    public Set<InputRectangle> getStartPieces() {
        return startPieces;
    }

    public void setStartPieces(Set<InputRectangle> startPieces) {
        this.startPieces = startPieces;
    }

    @OneToMany(mappedBy = "request", fetch = FetchType.EAGER)
    public Set<Frame> getFrames() {
        return frames;
    }

    public void setFrames(Set<Frame> frames) {
        this.frames = frames;
    }

}
